from django.db import models

from mptt.models import TreeForeignKey, MPTTModel


# Create your models here.


class UserInfo(models.Model):
    username = models.CharField(max_length=32, verbose_name='用户名', db_index=True)  # db_index 为用户名字段创建索引，后面查询的时候会很快
    password = models.CharField(max_length=32, verbose_name='密码')
    email = models.EmailField(max_length=32, verbose_name='邮箱')
    mobile_phone = models.CharField(max_length=32, verbose_name='手机号', null=True, blank=True)


class Tree(MPTTModel):
    name = models.CharField(max_length=32, verbose_name='目录名称', null=True, blank=True, )
    parent = TreeForeignKey('self', null=True, blank=True, related_name='children', on_delete=models.CASCADE)

    class MPTTMeta(object):
        order_insertion_by = ['name']

    def __str__(self):
        return self.name

class Wiki(models.Model):
    title = models.CharField(max_length=32, verbose_name='标题')
    content = models.TextField(verbose_name='内容')
    parent = models.ForeignKey('self', null=True, blank=True, related_name='children',on_delete=models.CASCADE)
